﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace GenerateDataBaseLibrary
{

    //The class that represents the root section
    public class PipelineConfig : ConfigurationSection
    {
        [ConfigurationProperty("assemblyName", IsRequired = true)]
        public string AssemblyName
        {
            get { return (string)this["assemblyName"]; }
        }

        [ConfigurationProperty("vendor", IsRequired = true)]
        public VendorElement Vendor
        {
            get { var vendor = (VendorElement)base["vendor"]; return vendor; }
        }
    }
    
    //This should be the nested one
    public class VendorElement : ConfigurationElement
    {
        [ConfigurationProperty("name", IsRequired = true)]
        public string Name
        {
            get { return (string)this["name"]; }
        }

        [ConfigurationProperty("setting", IsRequired = true)]
        public SettingElement Config
        {
            get { var config = (SettingElement)base["setting"]; return config; }
        }

        protected override bool IsModified()
        {
            bool ret = base.IsModified();
            return ret;
        }


        protected override bool SerializeElement(System.Xml.XmlWriter writer, bool serializeCollectionKey)
        {
            bool ret = base.SerializeElement(writer, serializeCollectionKey);
            return ret;
        }
    }

    //This class will represen the element inside the vendor which is inside the pipe line
    public class SettingElement : ConfigurationElement
    {
        [ConfigurationProperty("incomingFileType", IsRequired = true)]
        public string IncomingFileType
        {
            get { return (string)this["incomingFileType"]; }
        }

        protected override bool IsModified()
        {
            bool ret = base.IsModified();
            return ret;
        }


        protected override bool SerializeElement(System.Xml.XmlWriter writer, bool serializeCollectionKey)
        {
            bool ret = base.SerializeElement(writer, serializeCollectionKey);
            return ret;
        }


    }

    //This class will help get an element from the collection of setting
    [ConfigurationCollection(typeof(SettingElement))]
    public class SettingCollection : ConfigurationElementCollection
    {
        public SettingElement this[int index]
        {
            get { return (SettingElement)BaseGet(index); }
            set { if (BaseGet(index) != null) { BaseRemoveAt(index); } BaseAdd(index, value); }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new SettingElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((SettingElement)element).IncomingFileType;
        }
    }
    //This class will, I think you missed it it helps get an element from the collection of setting
    [ConfigurationCollection(typeof(SettingElement))]
    public class VendorCollection : ConfigurationElementCollection
    {
        public VendorElement this[int index]
        {
            get { return (VendorElement)BaseGet(index); }
            set { if (BaseGet(index) != null) { BaseRemoveAt(index); } BaseAdd(index, value); }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new VendorElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((VendorElement)element).Name;
        }
    }



}
